package zucc.edu.repay.dao;

import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.Transaction;

import Bean.repay;
import Util.BaseException;
import Util.HibernateUtil;

public class RepayDao {
	public void delRepay(repay repay) {
		// TODO �Զ����ɵķ������
		Session s = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction tx = s.beginTransaction();
		s.delete(repay);
		tx.commit();
		
	}
	
	public void addRepay(repay repay) {
		// TODO �Զ����ɵķ������
		Session s = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction tx = s.beginTransaction();
		s.save(repay);
		tx.commit();
				
	}
	
	public void updateRepay(repay repay) {
		// TODO �Զ����ɵķ������
		Session s = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction tx = s.beginTransaction();
		s.update(repay);
		tx.commit();
		
	}
	
	public repay searchRepay(String repayid) throws BaseException{
		// TODO �Զ����ɵķ������
		Session s = HibernateUtil.getSessionFactory().getCurrentSession();
		Transaction tx = s.beginTransaction();
		String hql = "from repay where repayid = '" + repayid + "'";
		Query qry = s.createQuery(hql);
		Object repay = qry.uniqueResult();
		tx.commit();
		return (repay)repay;
	}
	
	public List<repay> serarchAllRepay(){//�������û�
		Session s = HibernateUtil.getSessionFactory().getCurrentSession(); 
		Transaction tx = s.beginTransaction();
        String hql = "from repay";  
        Query query = s.createQuery(hql);  
        List<repay> roles = query.list();  
        tx.commit();
        return roles; 
}
}
